package Registration;


import dbmanager.DBManager;
import java.io.RandomAccessFile;
import java.sql.*;

import control.Control;
import utility.SplitString;

public class ModShortName 
{

	String Filename = "old.csv";
	String path = "C:\\Item\\";
	
	String Filename1 = "Error.csv";
	//String path1 = "D:\\Cdrive\\C-DRIVE\\Register\\Final\\";
	
	DBManager db;
	String sqlTable = "master_table";
	ResultSet rs;
	DefaultSupString dss;
	String supstr;
	
	RandomAccessFile random;
	RandomAccessFile Error;
	SplitString split = new SplitString();
	int counter=0;
	void addShortName()
	{
		try
		{
			db = new DBManager();
			db.getConnect();
			random = new RandomAccessFile(path+Filename,"r");
			Error  = new RandomAccessFile(path+Filename1,"rws");
			String src = random.readLine();
			while((src=random.readLine() )!= null)
			{
				try 
				{
					String record[] = src.split("\t");
					System.out.println("Item name : "+record[0]);
					
					String itemname = record[0];
					String short_name = record[1];
					String message = "11 property_details mod*\""+itemname+"\"$short_name:\""+short_name+"\"#891";
					
					Control controlClassObj = new Control("+911234567891",message,db);
					controlClassObj.messageProcessing();
					String temp = controlClassObj.requestProcess().toString();
					if(temp.contains("error"))
						Error.writeBytes(message+"\n");
					else
						counter++;
				} 
				catch (NullPointerException npe) 
				{
					npe.printStackTrace();
				}
			}
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		System.out.println(counter+" No of items are updated");
	}
		
	public static void main(String[] args) 
	{
		ModShortName mod = new ModShortName();
		mod.addShortName();
	}
}
